package com.id.supaclean.dao

import android.content.Context
import androidx.core.content.edit
import com.id.supaclean.MyApplication
import com.id.supaclean.utils.asTime

/**
 * Created by YiGo on 2022/6/15.
 */
object KeyDao {
    fun refreshScanTime() {
        sharedPreferences().edit {
            putLong("last_scan_time", System.currentTimeMillis())
            apply()
        }
    }

    fun getCurrentLastScanTime(): String {
        return sharedPreferences().getLong("last_scan_time", 0).let {
            if (it == 0L) "You haven't had a scan yet"
            else "Last scan:"+it.asTime("HH:mm")
        }
    }



//    fun refreshPurchaseState() {
//        sharedPreferences().edit {
//            putBoolean("is_purchased", true)
//            apply()
//        }
//    }
//
//    fun getCurrentPurchaseState(): Boolean {
//        return sharedPreferences().getBoolean("is_purchased", false)
//    }


    private fun sharedPreferences() =
        MyApplication.appContext.getSharedPreferences("supa_clean", Context.MODE_PRIVATE)

}